package com.example.word.viewModels

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.word.data.room.Word
import com.example.word.repositories.WordRepository
import kotlinx.coroutines.launch

class WordViewModel(private val wordRepository: WordRepository) : ViewModel() {

    fun getAllWords() =
        wordRepository.getAllWords()
    fun findWordsWithPattern(pattern: String): LiveData<List<Word>> =
        wordRepository.findWordsWithPattern(pattern)

    fun insertWords(vararg word: Word) {
        viewModelScope.launch {
            wordRepository.insertWords(*word)
        }
    }

    fun deleteAllWords() {
        viewModelScope.launch {
            wordRepository.deleteAllWords()
        }
    }

    fun updateWords(vararg words: Word) {
        viewModelScope.launch {
            wordRepository.updateWords(*words)
        }
    }

    fun deleteWords(vararg words: Word) {
        viewModelScope.launch { wordRepository.deleteWords(*words) }
    }


}